<?php
class PayController extends Controller{
	//order,order_goods表数据添加
	public function add(){
		if(isset($_SESSION['user'])){
			//order表数据添加
			$_POST['address']=$_POST['province'].$_POST['city'].$_POST['area'].$_POST['street'];
			// p($_POST['address']);exit;
			$_POST['addtime']=time();
			$_POST['order_sn']=date('Ymdhis',time());
			$_POST['user_id']=$_SESSION['user']['uid'];
			if($oid=M('order1')->add()){
				//order_goods表数据添加
				foreach ($_SESSION['cart']['goods'] as $g) {
					$data['order_id']=$oid;
					$data['goods_name']=$g['goods_name'];
					$data['goods_price']=$g['price'];
					$data['goods_number']=$g['num'];
					$data['goods_id']=$g['gid'];
					$data['goods_attr']=$g['attr_value'];
					$data['goods_sn']='';
					M('order_goods')->add($data);
				}
			}
			$this->success('订单提交成功','pay');
		}else{
			go('Login/login');
		}	
	}

	public function pay(){
		$map['user_id']=$_SESSION['user']['uid'];
		$address=M('order1')->where($map)->find();
		$this->assign('address',$address);
		$this->display();
	}
		
}
?>